home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The 640 MEG Shareware Studio 2
/
The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO
/
pascal
/
tpb4_src.zip
/
DOWNLOAD.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1988-09-13
|
22KB
|
641 lines
{ TPBoard 4.2 Copyright (c) 1987,88 by Jon Schneider & Rick Petersen
Portions Copyright (c) 1986,87 by Steve Fox and Les Archambault
Last modified :: 9-9-88 8:26 pm
}
{$R-} {Range checking off}
{$B-} {Boolean complete evaluation off}
{$S-} {Stack checking off}
{$I+} {I/O checking on}
{$N-} {No numeric coprocessor}
Unit Download;
Interface
Uses
TPCrt, Dos, TAccess, Globals, TPSTRING,
TPDOS, Core1, Core2, Dirs, Extract;
procedure SendXmodem(sendmode : Char);
{==========================================================================}
Implementation
procedure Test_Download_Ratio(var ok_to_send : Boolean; fnum : Integer);
var
Close : Integer;
i, x : LongInt;
begin
if (user_rec.ratio > 0) and (ok_to_send) then
begin
case CreditType of
Points :
Close := 20;
Kilobytes :
Close := 100;
Files :
Close := 5;
end;
x := user_rec.Download;
x := x+fnum;
if x = 0 then
x := 1;
i := user_rec.upload+1;
if (((i*user_rec.ratio) div x) < 2) and (((i*user_rec.ratio) mod x)
< Close) then
begin
WriteLn(Com);
WriteLn(Com, 'You are getting close to your download limit.');
WriteLn(Com);
end;
if ((i*user_rec.ratio) div x) < 1 then
begin
ok_to_send := False;
WriteLn(Com);
WriteLn(Com, 'Unable to send files until some uploads are received.');
WriteLn(Com);
end;
end;
end;
procedure Update_Newin(Xfrname : DosFileName);
var
i : LongInt;
t : tad_array;
begin
SetSect(HomName);
FindKey(NewinName, i, Xfrname);
if OK then
begin
with nwin_rec do
begin
Seek(nwin_file, i);
Read(nwin_file, nwin_rec);
Inc(dnloads);
GetTAD(t);
last_dnload := t;
Seek(nwin_file, i);
Write(nwin_file, nwin_rec);
FlushAny(nwin_file)
end;
end;
end;
procedure SendXmodem(sendmode : Char);
{ Send a file using Xmodem protocol }
var
OK, ok_to_send,
protocol_ok : Boolean;
This : FilePtr;
Xfrname,
TempXfrname : DosFileName;
Batch_Xfrname : Str100;
down_size : string[8];
XfrFile : untype_file;
mm, ss,
size, fnum,
pnum, tot_size : Integer;
i, kblocks : LongInt;
Fnames : fname_array;
fsize : array[1..10] of Integer;
mode : StrPr;
tot_send_time : Real;
procedure Send_a_File;
procedure Call_Dsz(var Xfrname : DosFileName;
remaining : LongInt;
sendmode : Char;
var ok_to_send : Boolean);
var
mm, ss,
time_on,
time_left : Integer;
i : LongInt;
begin {Call_Dsz}
Str(rate, baud);
OK := True;
errcode := 0;
remaining := remaining div 128;
case sendmode of
'X' :
mode := 'Xmodem CRC';
'Y' :
mode := 'Ymodem';
'Z' :
mode := 'Zmodem';
'C' :
mode := 'Xmodem Checksum';
'Q' :
mode := 'Ymodem-G (Qmodem)';
'O' :
mode := 'Xmodem OverThruster';
end;
timer(time_on, time_left);
send_time(remaining, mm, ss);
kblocks := remaining div 8;
if remaining mod 8 <> 0 then
Inc(kblocks);
if mm > time_left then
begin
WriteLn(Com, 'Insufficient time remaining.');
SetSect(SetName);
OK := False
end;
if OK then
begin
case CreditType of
Points :
begin
FindKey(NewinName, i, Xfrname);
if Taccess.OK then
begin
with nwin_rec do
begin
Seek(nwin_file, i);
Read(nwin_file, nwin_rec);
fnum := PointValue;
end;
end;
end;
Kilobytes :
fnum := kblocks;
Files :
fnum := 1;
end;
Test_Download_Ratio(ok_to_send, fnum);
if (not ok_to_send) then
begin
SetSect(SetName);
OK := False
end;
end;
if OK then
begin
WriteLn(Com);
WriteLn(Com, yellow, 'Download Time: ',
white, mm, ' minutes ', ss, ' seconds');
WriteLn(Com, yellow, 'Download Size: ',
white, remaining, ' records, ', kblocks, ' 1k blocks');
if CreditType = Points then
WriteLn(Com, yellow, 'Cost of Files: ', white, fnum, ' points');
WriteLn(Com, yellow, 'Protocol Type: ', white, mode);
Write(Com, yellow, 'File Selected: ', white, Xfrname);
if in_arc then
WriteLn(Com, green, ' (Use ''.ARC'' for your filename)')
else
WriteLn(Com);
WriteLn(Com);
WriteLn(Com, yellow, 'Several Ctrl-X''s Aborts Transfer');
WriteLn(Com, cyan);
SetSect(HomName);
Ch_Wait;
ScrollOn;
case sendmode of
'X', 'C' :
mode := 'sx';
'Y' :
mode := 'sx -k';
'Z' :
mode := 'sz';
'Q' :
mode := 'sx -g';
'O' :
mode := 'so';
'B' :
mode := 'sb -k';
'G' :
mode := 'sb -g';
end;
errcode := ExecDos(DSZPath+' handshake on '+mode+' '+SetName
+'\'+Xfrname, False, nil);
if errcode = 0 then errcode := DosExitCode;
Ch_Init;
Ch_Set(rate);
ScrollOff;
SetSect(SetName);
if (not Ch_Carck) then
begin
errcode := 1;
SetSect(HomName);
log(12, 'sending file');
SetSect(SetName);
mdhangup;
remote_online := False;
end;
end;
if errcode <> 0 then
OK := False;
if OK then
begin
WriteLn(Com);
WriteLn(Com, 'Transfer sucessfully completed.');
end
else
ok_to_send := False;
end; {Call_Dsz}
begin {Send_a_File}
if in_library then
This := LibBase
else if in_arc then
This := ArcBase
else
This := DirBase;
while (This <> nil) and (Xfrname <> compress_fn(This^.fname)) do
This := This^.next;
if This <> nil then
begin
SetSect(HomName);
case sendmode of
'Z' :
log(15, Xfrname);
'G', 'Q' :
log(17, Xfrname)
else
log(5, Xfrname);
end;
SetSect(SetName);
if in_library then
begin
Assign(libr_file, LibReq);
Reset(libr_file, 1);
Seek(libr_file, (This^.index*128));
WriteLn(Com, 'Extracting member file...');
WriteLn(Com);
if (diskfree(Ord(Upcase(SetDrv[1]))-64) > (This^.fsize*128)) then
ExtractLbr(Xfrname, (This^.fsize*128), ok_to_send)
else
ok_to_send := False;
Close(libr_file);
if ok_to_send then
begin
SetSect(SetName);
Assign(XfrFile, Xfrname);
Reset(XfrFile, 1);
SetSect(HomName);
Call_Dsz(Xfrname, FileSize(XfrFile), sendmode, ok_to_send);
Close(XfrFile);
Erase(XfrFile);
end;
end
else if in_arc then
begin
SetSect(HomName);
if ok_to_send then
begin
SetSect(HomName);
WriteLn(Com, 'Extracting member file...');
WriteLn(Com);
ExtractArc(Xfrname, ok_to_send);
if ok_to_send then
begin
SetSect(SetName);
Assign(XfrFile, Xfrname);
Reset(XfrFile, 1);
SetSect(HomName);
Call_Dsz(Xfrname, FileSize(XfrFile), sendmode, ok_to_send);
Close(XfrFile);
Erase(XfrFile);
end;
end;
end
else
begin
Assign(XfrFile, Xfrname);
Reset(XfrFile, 1);
SetSect(HomName);
Call_Dsz(Xfrname, FileSize(XfrFile), sendmode, ok_to_send);
Close(XfrFile)
end;
SetSect(HomName);
if ok_to_send then
begin
log(7, '');
case CreditType of
Points :
begin
FindKey(NewinName, i, Xfrname);
if Taccess.OK then
begin
with nwin_rec do
begin
Seek(nwin_file, i);
Read(nwin_file, nwin_rec);
user_rec.Download := user_rec.Download+PointValue;
end;
end;
end;
Kilobytes :
user_rec.Download := user_rec.Download+kblocks;
Files :
Inc(user_rec.Download);
end;
end
else
log(8, '');
end
else
begin
WriteLn(Com, 'Could not locate ', Xfrname, ' in this file section.');
ok_to_send := False;
SetSect(HomName);
log(8, 'Not Found')
end;
end; {Send_a_File}
begin { SendXmodem }
if (not(sendmode in ['G', 'Q'])) then
protocol_ok := True
else if (not AllowMNP) then
protocol_ok := False
else if cmd_tail and (StUpcase(ParamStr(3)) = 'MNP') then
protocol_ok := (ParamStr(4) = '/Arq')
else if cmd_tail then
protocol_ok := True
else
protocol_ok := mnp;
ok_to_send := protocol_ok;
fnum := 0; {total number of files to send}
pnum := 0; {total number of points}
if (sendmode in ['G', 'B', 'Z']) and (not in_library) and (not in_arc) and (ok_to_send) then
begin
Batch_Xfrname := '';
WriteLn(Com);
case sendmode of
'Z' :
log(15, 'BATCH');
'G' :
log(17, 'BATCH')
else
log(5, 'BATCH');
end;
repeat
ok_to_send := Online;
if ok_to_send then
Xfrname := prompt('Filenames (wildcards ok)', 80, 'ES');
if (Xfrname <> ' ') and (ok_to_send) then
begin
This := DirBase;
Batch_Xfrname := Batch_Xfrname+' '+Xfrname;
Xfrname := Expand_Filename(Xfrname);
while (This <> nil) and (ok_to_send) do
begin
if fnum > 10 then
ok_to_send := False;
if (Equal_names(Xfrname, This^.fname)) and ok_to_send then
begin
Inc(fnum);
Fnames[fnum] := compress_fn(This^.fname);
fsize[fnum] := This^.fsize;
if CreditType = Points then
begin
TempXfrname := Fnames[fnum];
FindKey(NewinName, i, TempXfrname);
if Taccess.OK then
begin
with nwin_rec do
begin
Seek(nwin_file, i);
Read(nwin_file, nwin_rec);
pnum := pnum+PointValue;
end;
end;
end;
end;
This := This^.next;
end;
end; {xfrname<>' ' and ok to send}
until (Xfrname = ' ') or (not mult_cmds) or (not ok_to_send);
if (fnum > 0) and (fnum < 11) and (ok_to_send) then
begin
tot_size := 0;
tot_send_time := 0;
Batch_Xfrname := '';
for i := 1 to fnum do
begin
size := fsize[i] shr 3; {divide by 8 recs / K}
if fsize[i] mod 8 <> 0 then
Inc(size);
if Odd(size) then
Inc(size);
tot_size := tot_size+size;
tot_send_time := tot_send_time+(fsize[i]*23.0/rate);
Batch_Xfrname := Batch_Xfrname+' '+Fnames[i];
end;
mm := Trunc(tot_send_time);
ss := Round(60.0*Frac(tot_send_time));
WriteLn(Com);
WriteLn(Com, yellow, 'Total # Files: ', white, fnum);
if CreditType = Points then
WriteLn(Com, yellow, 'Cost of Files: ', white, pnum, ' points');
WriteLn(Com, yellow, 'Download Time: ', white, mm, ' minutes ', ss, ' seconds');
WriteLn(Com, yellow, 'Download Size: ', white, tot_size, 'k');
Write(Com, yellow, 'Protocol Type: ', white);
case sendmode of
'B' :
WriteLn(Com, 'Ymodem Batch');
'G' :
WriteLn(Com, 'Ymodem-G Batch (DSZ)');
'Z' :
WriteLn(Com, 'Zmodem');
end;
Write(Com, yellow, 'File Selected: ', white);
for i := 1 to Length(Batch_Xfrname) do
begin
if (WhereX > 68) and (Batch_Xfrname[i] = ' ') then
begin
WriteLn(Com);
Write(Com, ' ');
end;
Write(Com, Batch_Xfrname[i]);
end;
WriteLn(Com);
WriteLn(Com);
WriteLn(Com, yellow, 'Several Ctrl-X''s Aborts Transfer');
WriteLn(Com, cyan);
timer(time_on, time_left);
if time_left < mm then
begin
WriteLn(Com, 'Not enough time for transfer.');
ok_to_send := False;
end;
end {fnum>0 and fnum<11}
else {no filenames or too many files}
begin
ok_to_send := False;
if fnum > 10 then
WriteLn(Com, 'Max. of 10 Files.')
else
WriteLn(Com, 'No files by that name found in this section.');
end;
SetSect(HomName);
case CreditType of
Points :
fnum := pnum;
Kilobytes :
fnum := tot_size;
end;
if ok_to_send then
Test_Download_Ratio(ok_to_send, fnum);
if ok_to_send then
begin
Assign(ext_log, ZmdmLogName);
if ExistFile(ZmdmLogName) then
Erase(ext_log);
Ch_Wait;
ScrollOn;
case sendmode of
'Z' :
mode := 'sz';
'B' :
mode := 'sb -k';
'G' :
mode := 'sb -g';
end;
SetSect(SetName);
errcode := ExecDos(DSZPath+' handshake on '+mode+' '+Batch_Xfrname, False, nil);
SetSect(HomName);
Ch_Init;
Ch_Set(rate);
ScrollOff;
Delay(1000);
WriteLn(Com);
ok_to_send := False;
Assign(ext_log, ZmdmLogName);
{$I-}
Reset(ext_log) {$I-} ;
if IoResult = 0 then
begin
while not EoF(ext_log) do
begin
ReadLn(ext_log, ext_log_rec);
if (not(ext_log_rec[1] in ['E', 'L'])) then
begin
ok_to_send := True;
repeat
Delete(ext_log_rec, 1, 1)
until Pos(' ', ext_log_rec) <> 1;
down_size := '';
repeat
down_size := down_size+ext_log_rec[1];
Delete(ext_log_rec, 1, 1);
until ext_log_rec[1] = ' ';
Delete(ext_log_rec, 1, 42);
OK := Str2Long(down_size, kblocks);
if OK then
kblocks := kblocks div 1024
else
kblocks := 0;
if Pos(' ', ext_log_rec) <> 0 then
Delete(ext_log_rec, Pos(' ', ext_log_rec), 10);
Xfrname := ext_log_rec;
if in_arc then
Update_Newin(ArcReq)
else if in_library then
Update_Newin(LibReq)
else
Update_Newin(Xfrname);
case sendmode of
'Z' :
log(15, Xfrname);
'G' :
log(17, Xfrname)
else
log(5, Xfrname);
end;
case CreditType of
Points :
begin
FindKey(NewinName, i, Xfrname);
if Taccess.OK then
begin
with nwin_rec do
begin
Seek(nwin_file, i);
Read(nwin_file, nwin_rec);
user_rec.Download := user_rec.Download+PointValue;
end;
end;
end;
Kilobytes :
user_rec.Download := user_rec.Download+kblocks;
Files :
Inc(user_rec.Download);
end;
end
else
ok_to_send := False;
end;
Close(ext_log);
end;
if ok_to_send then
begin
log(7, 'BATCH');
WriteLn(Com, 'Batch Transfer Complete.');
end
else
begin
log(8, 'BATCH');
WriteLn(Com, 'Aborting Batch Transfer.');
end;
end;
end {sendmode=B and not in library and ok to send}
else if (ok_to_send) then
begin
SetSect(HomName);
Test_Download_Ratio(ok_to_send, fnum);
if ok_to_send then
begin
Xfrname := prompt('File name', 12, 'ES');
if Xfrname <> ' ' then
Xfrname := correct_fn(Xfrname)
else
Xfrname := '';
if Xfrname <> '' then
Send_a_File;
SetSect(HomName);
if (ok_to_send) and (Xfrname <> '') then
begin
if in_arc then
Update_Newin(ArcReq)
else if in_library then
Update_Newin(LibReq)
else Update_Newin(Xfrname);
end;
end;
end
else if (not protocol_ok) then
begin
WriteLn(Com);
WriteLn(Com, 'Sorry, that protocol requires an MNP connection.')
end;
end; {Send Xmodem}
end. { of DOWNLOAD.PAS}